//**************************************************
//	Digit Widgets Angles Module
// 	Object Manipulation by Angle and Distance
//	Made to be called from Hyperlinked Digit_Widgets Script
//
//	Version 1.0 - Digit Widgets Standard Version
//**************************************************
<zscriptinsert,"Digit_Widgets_Common_Std.txt">
[PD]
[FontSetColor,255,200,0]Angle Functions[FontSetColor,160,160,160]
[PD]
//***************************
//Angle Manipulation Variables
//***************************
[VarDef,xtmp,0]
[VarDef,ytmp,0]
[VarDef,ztmp,0]
[VarDef,tmp,0]
[VarDef,tmp1,0]
[VarDef,XD1,0]
[VarDef,YD1,0]
[VarDef,ZD1,0]
[VarDef,aincr,0]
[VarDef,zincr,0]
[VarDef,Trad,0]
[VarDef,ypt,0]
[VarDef,xpt,0]
[VarDef,zpt,0]
[VarDef,recip,0]
[VarDef,Dmult,1]
[VarDef,DIST,0]
[VarDef,ZSlope,0]
[varDef,pangle,0]
[iSlider,"Distance",0,.1,-1000,1000,"Select Distance",[VarSet,DistToMark,zscript:Distance],0,[TextCalcWidth,Distance1453]]
[iSlider,"XYAngle",0,.1,-1000,1000,"Select Angle",[VarSet,dangle,zscript:XYAngle],0,[TextCalcWidth,XYAngle12345]]
[iSlider,"ZAngle",0,.1,-1000,1000,"Select Z Angle + or -",[VarSet,ZSlope,zscript:ZAngle],0,[TextCalcWidth,ZAngle123456]]
[iSlider,"AngleIncr",0,.1,-360,360,"Select Angle Increment  ",[VarSet,aincr,zscript:AngleIncr],0,[TextCalcWidth,AngleIncr4123]]
[iSlider,"ZAngleIncr",0,.1,-360,360,"Select ZAngle Increment ",[VarSet,zincr,zscript:ZAngleIncr],0,[TextCalcWidth,AngleIncr4123]]
[iSwitch,"Snapit",0,"Perform Snapshot"] 
[iSwitch,"DoSize",0,"Size to Position"] 
[iSwitch,"FromMark",0,"Center Object at current Mark"] 
[PD]

[iButton," Calc_Angle ","Calculate Dist and Angle to Mark",
	[TransformGet,IcurrX,IcurrY,IcurrZ,IcurrXS,IcurrYS,IcurrZS]
	[RoutineCall,GetAngle,IcurrX,MarkX(MarkIndex),IcurrY,MarkY(MarkIndex)]
	[ISet,zscript:XYangle,dangle]
	[RoutineCall,GetDistance,IcurrX,MarkX(MarkIndex),IcurrY,MarkY(MarkIndex)]
	[ISet,zscript:Distance,DistToMark]
]


[iButton," Place_angle ","Use Dist and Angle to Place object",
	[if,[iGet,zscript:FromMark],
		[TransformSet,MarkX(MarkIndex),MarkY(MarkIndex),MarkZ(MarkIndex),MarkXS(MarkIndex),MarkYS(MarkIndex),MarkZS(MarkIndex)]
	]
	
	[TransformGet,IcurrX,IcurrY,IcurrZ,IcurrXS,IcurrYS,IcurrZS,currxr,curryr,currzr]

	[VarSet,DIST,DistToMark]

	//xy position
	[RoutineCall,GetPosition,dangle,Zslope,DIST]

	[VarSet,XD1,IcurrX+xpt]
	[VarSet,YD1,IcurrY+ypt]
	[VarSet,ZD1,IcurrZ+zpt]


	//Draw new position
	[TransformSet,XD1,YD1,ZD1]


	[if,[iGet,zscript:DoSize],
		[TransformGet,IcurrX,IcurrY,IcurrZ,IcurrXS,IcurrYS,IcurrZS]
		[RoutineCall,DepthCalc]
	]//Endif



	[if,[iGet,zscript:Snapit],
		[IPress,Transform:Snapshot]
	]//endif


	//add XY Angle increment if there is any
	[VarAdd,dangle,aincr]
	[if,dangle>360,
		[VarSet,dangle,dangle-360]]

	[if,dangle<-360,
		[VarSet,dangle,dangle+360]]

	[ISet,zscript:XYAngle,dangle]
	
	[VarAdd,ZSlope,zincr]
	[if,ZSlope>360,
		[VarSet,ZSlope,ZSlope-360]]
	[if,ZSlope<-360,
		[VarSet,ZSlope,ZSlope+360]]
	
	[ISet,zscript:ZAngle,Zslope]
	//move back to mark if enables
]
[PD]
[pd][penMove,0,8]
<zscriptinsert,"Widgets_Index_Include_Std.txt">
[pd][penMove,0,8]
\C00e0e0About This ZScript:\Cc0c0c0
This script will allow you to move and object around a defined Postion Marker or in space by providing a \Cffa000Angle\Cc0c0c0 and \Cffa000Distance\Cc0c0c0 value. An increment value for both XY and Z angle can be used to automatically increment the Angle value causing the object to be drawn at a different point in space the next time the \Cffa000Place Angle\Cc0c0c0 button is used. 
The \Cffa000Note about ZAngle\Cc0c0c0 A \Cffa000ZAngle\Cc0c0c0 of between 0 and 180 degrees will move the object away from you. A value of 90 degrees is the Max in the Positive Z direction. Conversly, a \Cffa000ZAngle\Cc0c0c0of 180 to 360 degrees moves the object toward you or the negative Zdirection and a \Cffa000ZAngle\Cc0c0c0of of 270 is the Max.
The \Cffa000Important\Cc0c0c0 to use this script you must be holding the desired object in either Move, Scale or Rotation mode, in other words the Gyro must be visible for the script to manipulate the desired object.
[PD]
[iButton,"Example ","Angle Widget Example",
	[if,[Ireset],
	[IcolorSet,239,234,30]
	[note,"I will select a Sphere, any object can be used however",zscript:example,0]
	[ISet,Tool:ItemInfo,8]
	[note,"Drag it onto Canvas",zscript:example,3]
	[CanvasClick,DocMidX,DocMidY,DocMidX+20,DocMidY+20]
	[IPress,Transform:Move]
	[note,"Notice that I am holding the object now in a Transform Move, Scale, or Rotation mode and that the Gyro is visible. Next I will use the Position Marker Widget feature and save its Position as Marker 1",zscript:example,0]
	[ISet,zscript:SelectMark,1]
	[Ipress,zscript:Save]
	[IPress,Transform:Snapshot]
	[note,"Next, I Set the Angle Distance to 50. This places the object 50 units away",zscript:example,0]
	[ISet,zscript:Distance,50]
	[note,"Then I set the AngleIncr to 20 so that each time I press the Place_Angle button it will automatically set the Angle +20 degrees. To go in the other direction I would use a negative number",zscript:example,0]
	[ISet,zscript:AngleIncr,20]
	[note,"Making sure that Snapit and FromMark Switch is on",zscript:example,3]
	[if,[IGet,zscript:Snapit],
	,
		[IToggle,zscript:Snapit]
	]
	[if,[IGet,zscript:FromMark],
	,
		[IToggle,zscript:FromMark]
	]
	[note,"Then we Press the Place_Angle button a few times to place the object at 20 degree increments 50 units from the mark",zscript:example,0]
	[loop,18,
		[IPress,zscript:Place_Angle]
		[Delay,1]
	]
	[note,"Play with the Zangle Increment to move in depth",zscript:example,0]
	[note,"Disable the FromMark switch and experiment with XYAngle and Zangle to make loops etc.. Make sure you set the distance to a smaller value if need be. Change the Angle and ZAngle Increment values positive and negative to change directions ",zscript:example,0]
	[note,"Use DoSize to automatically size your object based upon your ZDepth Reference that you have Set, you did set that didn't you :) The Default Reference is set to a 500 unit Area",zscript:example,0]
,//else
	[Note,"Aborting! Maybe another day eh?",,3]
]

]
[PD]
[PD]
[fontSetSizeSmall]\C00e0e0Standard Digit Widget Angle Revision 1.0, created by Digits\Cc0c0c0
